<template>
  <div class="box2">
    <el-form
      :model="ruleForm"
      :rules="rules"
      :inline="false"
      ref="ruleForm"
      label-width="200px"
      class="demo-ruleForm"
      size="medium"
    >
      <div class="must">
        <el-form-item label="申请人通信地址：" prop="applicantsCommAddr">
          <el-input v-model="ruleForm.applicantsCommAddr" placeholder="请填写申请人通信地址"></el-input>
        </el-form-item>
        <el-form-item label="申请人电子邮件：" prop="emailAddr">
          <el-input v-model="ruleForm.emailAddr" placeholder="请填写申请人通信地址"></el-input>
        </el-form-item>
        <el-form-item label="收文语言选择：" prop="languageFile">
          <el-radio-group v-model="ruleForm.languageFile">
            <el-radio class="input" :label="1">英语</el-radio>
            <el-radio class="input" :label="2">法语</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item label="申请人资格：" prop="applicantsStatus">
          <el-select v-model="ruleForm.applicantsStatus" filterable placeholder="请选择">
            <el-option
              v-for="item in qualification"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="代理人名称(中文)：" prop="proxyName">
          <el-input v-model="ruleForm.proxyName" placeholder="请填写代理人名称(中文)"></el-input>
        </el-form-item>
        <el-form-item label="代理人名称(英文)：" prop="proxyNameEn">
          <el-input v-model="ruleForm.proxyNameEn" placeholder="请填写代理人名称(英文)"></el-input>
        </el-form-item>
        <el-form-item label="代理人地址：" prop="proxyAddr">
          <el-input v-model="ruleForm.proxyAddr" placeholder="请填写"></el-input>
        </el-form-item>
        <el-form-item label="代理人电子邮件：" prop="proxyPostcode">
          <el-input v-model="ruleForm.proxyPostcode" placeholder="请填写"></el-input>
        </el-form-item>
        <el-form-item label="注册号：" prop="registryCode">
          <el-input v-model="ruleForm.registryCode" placeholder="请填写注册号"></el-input>
        </el-form-item>
        <el-form-item label=" 注册日期：" prop="registryDate">
          <el-date-picker v-model="ruleForm.registryDate" type="date" placeholder="选择日期"></el-date-picker>
        </el-form-item>
        <el-form-item label="申请号：" prop="appCode">
          <el-input v-model="ruleForm.appCode" placeholder="请填写申请号"></el-input>
        </el-form-item>
        <el-form-item label=" 申请日期：" prop="appDate">
          <el-date-picker v-model="ruleForm.appDate" type="date" placeholder="选择日期"></el-date-picker>
        </el-form-item>

        <el-form-item label=" 在先申请所在主管局：" prop="managePart">
          <el-input v-model="ruleForm.managePart" placeholder="在先申请所在主管局"></el-input>
        </el-form-item>

        <el-form-item label="初次申请号：" prop="initPhone">
          <el-input v-model="ruleForm.initPhone" placeholder="请填写初次申请号"></el-input>
        </el-form-item>
        <el-form-item label="初次申请日期：" prop="date1">
          <el-date-picker v-model="ruleForm.date1" type="date" placeholder="选择日期"></el-date-picker>
        </el-form-item>
        <el-form-item class="upload" label="商标样图：" prop="upload">
          <base-upload @getFile="getFile">
            <p
              class="imgHint"
            >提醒：左框为商标图样粘贴处。图样应当不大于80×80mm，不小于20×20mm。 以颜色组合或者着色图样申请商标注册的，应当提交着色图样并提交黑白稿1份；不指定颜色的，应当提交黑白图样。 以三维标志申请商标注册的，应当提交能够确定三维形状的图样，提交的商标图样应当至少包含三面视图。 以声音标志申请商标注册的，应当以五线谱或者简谱对申请用作商标的声音加以描述并附加文字说明； 无法以五线谱或者简谱描述的，应当使用文字进行描述；商标描述与声音样本应当一致。</p>
          </base-upload>
        </el-form-item>

        <el-form-item label="其他事项：">
          <ul class="other-box">
            <el-checkbox-group v-model="ruleForm.remarkId">
              <li>
                <el-checkbox label="1">要求保护颜色的，请作文字说明：</el-checkbox>
                <el-input type="textarea" v-model="ruleForm.protectColor"></el-input>
              </li>
              <li>
                <el-checkbox label="2">立体商标</el-checkbox>
              </li>
              <li>
                <el-checkbox label="3">声音商标</el-checkbox>
              </li>
              <li>
                <el-checkbox label="4">集体或证明商标</el-checkbox>
              </li>
              <li>
                <el-checkbox label="5">商标音译(拼音):</el-checkbox>
                <el-input v-model="ruleForm.yinyi"></el-input>
              </li>
              <li>
                <el-checkbox label="6">商标意译(英语或法语):</el-checkbox>
                <el-input v-model="ruleForm.yingyi"></el-input>
              </li>
              <li>
                <el-checkbox label="7">商标无含义</el-checkbox>
              </li>
            </el-checkbox-group>
          </ul>
        </el-form-item>
        <el-form-item label=" 商品或/和服务及其类别：">
          <h2 class="classes-title">
            <span>类别</span>
            <span>商品和/或服务</span>
          </h2>
          <span class="add-btn el-icon-circle-plus-outline" @click="addbtn"></span>
          <ul class="classes-box">
            <li v-for="(item,index) in ruleForm.mdlBusinessVoJson" :key="index">
              <el-input v-model="item.goodsServiceType2"></el-input>
              <el-input v-model="item.service2"></el-input>
            </li>
          </ul>
        </el-form-item>

        <el-form-item label="如有对具体国家作商品或/和服务及类别的限定，请注明：">
          <h2 class="classes-title">
            <span>指定缔约方</span>
            <span>申请保护的类别及商品和/或服务</span>
          </h2>
          <span class="add-btn el-icon-circle-plus-outline" @click="addbtn1"></span>
          <ul class="classes-box">
            <li v-for="(item,index) in ruleForm.mdlBusinessVoJson1" :key="index">
              <el-input v-model="item.goodsServiceType2"></el-input>
              <el-input v-model="item.service2"></el-input>
            </li>
          </ul>
        </el-form-item>

        <el-form-item label="同属协定和议定书缔约方：">
          <el-checkbox-group v-model="ruleForm.treatyman" class="statesbox">
            <el-checkbox
              v-for="(state,index) in states"
              :label="state.countryId"
              :key="index"
            >{{state.country}}</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="纯议定书缔约方：">
          <el-checkbox-group v-model="ruleForm.treatyman1" class="statesbox">
            <el-checkbox
              v-for="(state,index) in states1"
              :label="state.countryId"
              :key="index"
            >{{state.country}}</el-checkbox>
          </el-checkbox-group>
        </el-form-item>

        <el-form-item label="本申请交费方式:">
          <el-select v-model="ruleForm.paymentPipe" filterable placeholder="请选择">
            <el-option
              v-for="item in payclass"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <div class="btns">
            <el-button type="primary" @click="outStep">上一步</el-button>
            <el-button type="primary" @click="dialogVisible = true">提交并审核</el-button>
          </div>
        </el-form-item>
        <el-dialog
          class="dialog"
          :show-close="false"
          :center="true"
          :visible.sync="dialogVisible"
          width="460px"
          :before-close="handleClose"
        >
          <div class="hint">
            <img src="../../assets/imgs/branch.png" alt="提示图片" />
            <span>选择您想去办理的网点</span>
          </div>
          <el-form-item label="选择网点：" prop="branchNetworkId">
            <el-select v-model="ruleForm.branchNetworkId" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.deptId"
                :label="item.deptName"
                :value="item.deptId"
              >
                <span style="float: left">{{ item.deptName }}</span>
                <span style="float: right; color: #8492a6; font-size: 13px">{{ item.address }}</span>
              </el-option>
            </el-select>
          </el-form-item>
          <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="submitForm('ruleForm')">确 定</el-button>
          </div>
        </el-dialog>
        <el-dialog
          class="hintMsg"
          :show-close="false"
          title="温馨提示"
          :visible.sync="centerDialogVisible"
          width="462px"
        >
          <span>您的信息已提交，工作人员将在3-5日内对你的信息审核，审核通过后即可预约业务，审核结果将通过短信的方式发送给你。</span>
          <span slot="footer" class="dialog-footer">
            <el-button type="primary" @click="skip">确 定</el-button>
          </span>
        </el-dialog>
      </div>
    </el-form>
  </div>
</template>
<script>
import BaseUpload from "./BaseUpload";
export default {
  name: "internationalForm",
  components: {
    BaseUpload,
  },
  data() {
    return {
      //网点列表
      options: [],
      //提交成功弹出框变量
      centerDialogVisible: false,
      //网点弹出框控制变量
      dialogVisible: false,
      //提交表单
      formData: new FormData(),
      //表单唯一id
      classId: "",
      checkedCities: [],
      states: [],
      qualification: [
        {
          value: "申请人在中国设有真实有效的工商营业场所",
          label: "申请人在中国设有真实有效的工商营业场所",
        },
        {
          value: "或者申请人在中国设有住所(或总部)",
          label: "或者申请人在中国设有住所(或总部)",
        },
        {
          value: "或者申请人具有中国国籍",
          label: "或者申请人具有中国国籍",
        },
      ],
      payclass: [
        {
          value: "通过国家知识产权局向国际局转交规费",
          label: "通过国家知识产权局向国际局转交规费",
        },
        {
          value: "直接向国际局交纳规费",
          label: "直接向国际局交纳规费",
        },
      ],
      checkedCities1: [],
      states1: [],

      checkList: [],
      //填写的信息
      ruleForm: {
        applicantsCommAddr: "", //申请人通信地址
        emailAddr: "", //申请人电子邮件
        languageFile: "", //收文语言选择
        applicantsStatus: "", //申请人资格
        proxyName: "", //代理人名称(中文)
        proxyNameEn: "", //代理人名称(英文)
        proxyAddr: "", //代理人地址
        proxyPostcode: "", //代理人电子邮件
        registryCode: "", //注册号
        registryDate: "", //注册日期
        appCode: "", //申请号
        appDate: "", //申请日期
        managePart: "", //在先申请所在主管局
        initPhone: "", //初次申请号
        date1: "", //初次申请日期
        file: "", //商标样图
        remarkId: [], //其他事项id
        protectColor: "", //要求保护颜色的
        yinyi: "", //商标音译(拼音)
        yingyi: "", //商标意译(英语或法语)
        mdlBusinessVoJson: [
          {
            goodsServiceType2: "", //类别
            service2: "",
          },
        ],
        mdlBusinessVoJson1: [
          {
            goodsServiceType2: "", //类别
            service2: "",
          },
        ],
        treatyman: [], //同属协定和议定书缔约方
        treatyman1: [], //纯议定书缔约方
        paymentPipe: "", //本申请交费方式
        branchNetworkId: "",
      },
      rules: {
        applicantsCommAddr: [
          { required: true, message: "选项不能为空", trigger: "change" },
        ],
        emailAddr: [
          { required: true, message: "选项不能为空", trigger: "change" },
        ],
        languageFile: [
          { required: true, message: "选项不能为空", trigger: "change" },
        ],
        applicantsStatus: [
          { required: true, message: "选项不能为空", trigger: "change" },
        ],
        proxyName: [
          { required: true, message: "选项不能为空", trigger: "change" },
        ],
        proxyNameEn: [
          { required: true, message: "选项不能为空", trigger: "change" },
        ],
        proxyAddr: [
          { required: true, message: "选项不能为空", trigger: "change" },
        ],
        proxyPostcode: [
          { required: true, message: "选项不能为空", trigger: "change" },
        ],
        registryCode: [
          { required: true, message: "选项不能为空", trigger: "change" },
        ],
        registryDate: [
          { required: true, message: "选项不能为空", trigger: "change" },
        ],
        appCode: [
          { required: true, message: "选项不能为空", trigger: "change" },
        ],
        appDate: [
          { required: true, message: "选项不能为空", trigger: "change" },
        ],
        managePart: [
          { required: true, message: "选项不能为空", trigger: "change" },
        ],
        initPhone: [
          { required: true, message: "选项不能为空", trigger: "change" },
        ],
        date1: [{ required: true, message: "选项不能为空", trigger: "change" }],

        branchNetworkId: [
          { required: true, message: "选项不能为空", trigger: "change" },
        ],
      },
    };
  },

  mounted() {
    //获取从存储在路由中的classId
    this.classId = this.$route.query.id;
    //获取网点列表
    this.$http.get("trademark/system/dept/findDept").then((res) => {
      this.options = res.data.data;
    });
    this.getstate();
  },

  methods: {
    //返回上一步
    outStep() {
      this.$emit("wp", 1, "请填写申请业务信息");
    },
    //提示模板
    open1(msg, types = "success") {
      this.$notify({
        message: msg,
        type: types,
      });
    },
    //弹出框的选项确认框
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },
    //表单提交事件
    submitForm(formName) {
      // if(){

      // }
      let _this = this;
      this.$refs[formName].validate((valid) => {
        if (valid) {
          //每次提交重新生成新的FormData用于储存新的数据
          this.formData = new FormData();
          this.dialogVisible = false;
          //获取vuex中保存的步骤二中的数据
          let {
            name, //申请人中文名称applicantsName
            englishName, //申请人英文名称applicantsNameEn
            person_type,
            site, //申请人地址applicantsAppAddr
            phone, //申请人电话
            } = this.$store.state.storeDatas;

          this.formData.append("applicantsName", name);
          this.formData.append("applicantsNameEn", englishName);
          this.formData.append("applicantsAppAddr", site);
          this.formData.append("classId", this.classId);
          this.formData.append(
            "applicantsCommAddr",
            this.ruleForm.applicantsCommAddr
            );
          this.formData.append("emailAddr", this.ruleForm.emailAddr);
          this.formData.append("languageFile", this.ruleForm.languageFile);
          this.formData.append(
            "applicantsStatus",
            this.ruleForm.applicantsStatus
            );
          this.formData.append("proxyName", this.ruleForm.proxyName);
          this.formData.append("proxyNameEn", this.ruleForm.proxyNameEn);
          this.formData.append("proxyAddr", this.ruleForm.proxyAddr);
          this.formData.append("proxyPostcode", this.ruleForm.proxyPostcode);
          this.formData.append("registryCode", this.ruleForm.registryCode);
          this.formData.append(
            "registryDate",
            this.timedispose(this.ruleForm.registryDate)
            );
          this.formData.append("appCode", this.ruleForm.appCode);
          this.formData.append(
            "appDate",
            this.timedispose(this.ruleForm.appDate)
            );
          this.formData.append("managePart", this.ruleForm.managePart);
          this.formData.append("initPhone", this.ruleForm.initPhone);
          this.formData.append("date1", this.timedispose(this.ruleForm.date1));
          this.formData.append("file", this.ruleForm.file);

          this.formData.append( 
            "remarkId",
            JSON.stringify(this.ruleForm.remarkId)
            );

          this.formData.append("protectColor", this.ruleForm.protectColor);
          this.formData.append("yinyi", this.ruleForm.yinyi);

          this.formData.append("yingyi", this.ruleForm.yingyi);
          this.formData.append(
            "mdlBusinessVoJson",
            JSON.stringify(this.ruleForm.mdlBusinessVoJson)
            );
          this.formData.append(
            "treatyman",
            JSON.stringify(this.ruleForm.treatyman)
            );
          this.formData.append(
            "treatyman1",
            JSON.stringify(this.ruleForm.treatyman1)
            );

          this.formData.append("paymentPipe", this.ruleForm.paymentPipe);
          this.formData.append(
            "branchNetworkId",
            this.ruleForm.branchNetworkId
            );
          // this.formData.append("userId", "2");
          //配置请求头
          var config = {
            header: {
              "Content-Type": "multipart/form-data",
            },
          };
          // axios向后端发送数据
          this.$http
            .post("trademark/mdlBusiness/firstSubmit", this.formData, config)
            .then(function (response) {
              ////console.log(response)
              //若状态码不为200则不跳转
              if (response.data.code != 200) {
                _this.open1("提交失败", "error");
                return;
              }

              _this.centerDialogVisible = true;
            })
            .catch(function (error) {});
        } else {
          return false;
        }
      });
    },
    //跳转函数
    skip() {
      this.centerDialogVisible = false;
      this.open1("操作成功");
      this.$router.push({
        path: "/business/myBusiness/auditing",
      });
    },
    //获取图片列表
    getFile(data, data2) {
      this.ruleForm.file = data2[0];
    },
    addbtn() {
      this.ruleForm.mdlBusinessVoJson.push({
        goodsServiceType2: "",
        service2: "",
      });
    },
    addbtn1() {
      this.ruleForm.mdlBusinessVoJson1.push({
        goodsServiceType2: "",
        service2: "",
      });
    },
    // 处理时间
    timedispose(date) {
      return `${date.getFullYear()}-${this.zero(date.getMonth())}-${this.zero(
        date.getDate()
      )} ${this.zero(date.getHours())}:${this.zero(
        date.getMinutes()
      )}:${this.zero(date.getSeconds())}`;
    },
    zero(n) {
      return n > 10 ? n : "0" + n;
    },
    // 获取国家
    getstate() {
      this.$http
        .get("trademark/country/findAll", {
          params: {
            model: "1",
          },
        })
        .then((res) => {
          this.states = res.data.data;
        })
        .catch((err) => {});

      this.$http
        .get("trademark/country/findAll", {
          params: {
            model: "2",
          },
        })
        .then((res) => {
          this.states1 = res.data.data;
        })
        .catch((err) => {});
    },
  },
};
</script>
<style lang="less" scoped>
.btns {
  display: flex;
  justify-content: center;
  .el-button {
    margin: 0 20px;
  }
}
.box2 {
  display: flex;
  flex-direction: column;
  align-items: center;
  // margin-top: 100px;
  padding-right: 280px;
  width: 100%;
  min-height: 800px;
  .tle {
    font-size: 24px;
    color: #000;
  }
  .el-form {
    width: 100%;
  }
  .must,
  .select {
    display: flex;
    position: relative;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px 0 30px;
    margin-bottom: 80px;
    width: 100%;
    // border: 1px solid #bbbbbb;
    border-radius: 10px;
    .el-form-item {
      width: 680px;
    }
    .inline {
      display: flex;
      .el-form-item {
        margin: 0;
        width: 290px !important;
      }
    }
  }
  .el-dialog__body .el-form-item{
    margin: 0;
  }
  .must {
    margin-bottom: 20px;
  }
  .line {
    width: calc(100% - 280px);
    margin: 10px auto;
    height: 1px;
    border-top: 1px dashed #d9d9d9;
  }
  .imgHint {
    margin: 5px;
    font-size: 12px;
    line-height: 17px;
    color: #f5222d;
  }
  .affirm {
    font-size: 12px;
    color: #a0a3a5;
    a {
      text-decoration: none;
      color: #3685ff;
    }
  }
  .input {
    width: 190px;
  }
  .upload {
    margin: 20px 0;
  }
  .type-number {
    width: 250px;
  }
  .dialog-footer span{
    color: white !important; 
  }
  .inform {
    position: absolute;
    top: 10px;
    left: 260px;
    width: 500px;
    font-size: 12px;
    color: #a0a3a5;
    a {
      text-decoration: none;
      color: #3685ff;
    }
  }
  .tle {
    list-style: none;
    margin: 40px 0 20px;
    font-size: 24px;
    & ~ .tle {
      color: #bbb;
    }
  }
  .hint {
    color: #f5222d;
    padding: 15px 5px;
    background-color: #fff;
    .el-form-item__label {
      width: 150px;
    }
    img {
      width: 20px;
    }
  }
  .el-steps {
    width: 70%;
    height: 200px;
  }
  .el-button {
    //display: block;
    display: inline;
    margin: 0 20px;
    // background-color: #67c23a !important;
    // border-color: #67c23a !important;
  }

  .common .el-button {
    background-color: #fff !important;
    border-color: #bbb !important;
  }
}
.dialog-footer {
  // display: flex;
  justify-content: space-between;
  color: #fff;
  .lan {
    color: #fff;
    background-color: #2c9dfc !important;
    border-color: #2c9dfc !important;
  }
}

.dialog /deep/.el-form-item__label {
  width: 100px !important;
}
.dialog /deep/.el-form-item__content {
  margin-left: 100px !important;
}
.dialog /deep/.el-input {
  width: 250px;
}
.el-checkbox-group {
  line-height: 14px;
}
.is-checked/deep/.el-radio__inner,
.is-checked/deep/.el-checkbox__inner {
  border-color: #999999;
  background: #999999;
}
.el-radio/deep/.el-radio__inner:hover {
  border-color: #999999 !important;
}
.is-checked/deep/.el-radio__label,
.is-checked/deep/.el-checkbox__label {
  color: #333;
}
.is-focus .el-checkbox__inner {
  border-color: #999999 !important;
}
.el-checkbox/deep/.el-checkbox__inner:hover {
  border-color: #999999 !important;
}
.el-step__head.is-process {
  border-color: #f96900;
  color: #f96900 !important;
}
.hintMsg {
  /deep/.el-dialog__header {
    // display: flex;
    justify-content: center;
    font-weight: bold;
  }
  .dialog-footer {
    justify-content: center;
    .el-button {
      border-color: #2c9dfc !important;
      background: #2c9dfc !important;
    }
  }
}
.other-box {
  width: 100%;
  li {
    padding-top: 10px;
  }
}
.classes-box {
  width: 100%;

  li {
    margin-top: 10px;
    /deep/.el-input {
      &:nth-child(1) {
        width: 30%;
      }
      &:nth-child(2) {
        width: 70%;
      }
    }
  }
}

.add-btn {
  font-size: 25px;
  cursor: pointer;
  &:hover {
    color: #2c9dfc;
  }
}
.classes-title {
  width: 100%;
  span {
    text-align: center;
    display: inline-block;
    &:nth-child(1) {
      width: 30%;
      line-height: 40px;
    }
    &:nth-child(2) {
      width: 70%;
      line-height: 40px;
    }
  }
}
.statesbox {
  padding-top: 10px;
  .el-checkbox {
    margin-bottom: 20px;
  }
}

.sample-box {
  float: left;
  width: 332px;
  height: 110px;
  background-color: #ddd;
  margin-left: 20px;
}
.imgHint {
  float: left;
}
</style>